package com.qian.saas.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qian.saas.domain.Part;
import com.qian.saas.domain.Renwu;
import com.qian.saas.domain.Users;
import com.qian.saas.domain.Vo.RenwuVo;
import com.qian.saas.mapper.PartMapper;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/part")
@CrossOrigin
public class PartController {

    @Resource
    private PartMapper partMapper;

    @GetMapping("/list")
    public R list(String page, String limit){
        IPage<Part> mppage = new Page<>(Integer.parseInt(page), Integer.parseInt(limit));//参数一：当前页，参数二：每页记录数
        //分页
        IPage<Part> userIPage = partMapper.selectPage(mppage, null);
        List<Part> records = userIPage.getRecords();
        Map map = new HashMap<>();
        map.put("items", records);
        map.put("total", userIPage.getTotal());
        return R.success(map);
    }

    @GetMapping("/getall")
    public R getall(){
        List<Part> parts = partMapper.selectList(null);
        return R.success(parts);
    }
}
